#include "test.h"
#include "main.h"

#if 0
class Test_DynObj : public Test
{
	public:
	Test_DynObj() {}

	void check()
	{
		binary_0000();
	}

	void users() {}
	void bench() {}


	protected:

	class My_0000 : public DynObj
	{
		DECLARE_DYNOBJ(My_0000);
	};

	IMPLEMENT_DYNOBJ(My_0000);

	void binary_0000()
	{
		const int c1 = 12345678;
		const int c2 = 77747774;
		const std::string filename = Format("./tmp/%$.txt")%Test::nocolon(PF);
		{
			printf("# %s writing\n",filename.data());
			FileMappingDynamicSegment buffer(filename.data(),true,0666,64*1024);
			{	
				TOStorage s(buffer);
				s << TOStorage::DEC;
				s << TOStorage::BEGIN << c1 << TOStorage::END << c2;
				s << TOStorage::POP;
			}
		}
		
		{
			printf("# %s reading 1\n",filename.data());
			FileMappingConstSegment buffer(filename.data());
			int v1 = 0;
			int v2 = 0;
			{
				TIStorage s(buffer);
				try
				{
					s >> TIStorage::BEGIN >> v1 >> TIStorage::END;
				}
				catch(const Exception & xe)
				{
					printf("# exception %s\n",xe.text().data());
					s >> TIStorage::ABORT;
				}
				s >> v2;
				CHECKINT(c1,v1);
				CHECKINT(c2,v2);
			}
		}

		{
			printf("# %s reading 2\n",filename.data());
			FileMappingConstSegment buffer(filename.data());
			int v2 = 0;
			{
				TIStorage s(buffer);
				s >> TIStorage::BEGIN >> TIStorage::ABORT >> v2;
				CHECKINT(c2,v2);
			}
		}

		{
			printf("# %s reading 3\n",filename.data());
			FileMappingConstSegment buffer(filename.data());
			int v1 = 0;
			int v1bis = 0;
			int v2 = 0;
			{
				TIStorage s(buffer);
				try
				{
					s >> TIStorage::BEGIN >> v1 >> v1bis >> TIStorage::END;
				}
				catch(const Exception & xe)
				{
					printf("# exception %s\n",xe.text().data());
					s >> TIStorage::ABORT;
				}
				s >> v2;
				CHECKINT(c1,v1);
				CHECKINT(c2,v2);
			}
		}


	}



};

REGTEST(Test_TStorage)


#endif
